package jsyf.oa.dao.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import jsyf.com.dao.BaseJdbcDao;
import jsyf.oa.entity.system.RightEntity;
import jsyf.oa.idao.BaseDao;
import jsyf.oa.ientity.IBaseEntity;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class RightDao extends BaseDao{

    public RightDao() {
        this.iBaseEntity = new RightEntity();
    }

    public RightEntity getEntityById(String id){
        return (RightEntity) super.getIBaseEntityById(id);
    }
    public Boolean sort(String rightIds) {
        List<String> list = BaseJdbcDao.stringToList(rightIds);
        for (int i = 0; i < list.size(); i++) {
            JSONObject obj = new JSONObject();
            obj.put("ID", list.get(i));
            obj.put("SORT_NO", i);

            JSONObject objId = new JSONObject();
            objId.put("ID", list.get(i));
            super.update(iBaseEntity.getTableName(), obj, objId);
        }
        return true;
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json, RightEntity.class);
    }
}
